package com.ea.eadp.nexus.test.workflow.pc.parentemail;

import com.ea.eadp.nexus.test.common.TestUtil;
import org.openqa.selenium.WebDriver;
import org.testng.Assert;

import com.ea.eadp.nexus.test.common.SystemProperties;
import com.ea.eadp.nexus.test.pageDefinition.pc.RequireParentEmailPage;
import com.ea.eadp.nexus.test.workflow.WorkflowElement;
import com.ea.eadp.nexus.test.workflow.WorkflowElementArgument;

public class RequireParentEmailWorkflowElement extends WorkflowElement {
    
    protected RequireParentEmailPage page;
    
    public RequireParentEmailWorkflowElement(
        WebDriver driver, WorkflowElementArgument argument
    ) {
        super(driver, argument);
        page = new RequireParentEmailPage(driver);
    }
    
    @Override
    public void init() {
        super.init();
        page.initPage();
    }
    
    @Override
    public void doAction() {
        page.txt_parentEmail.sendKeys(args.parentEmail);
        page.btn_next.click();
    }
    
    @Override
    public void doVerification() {
        super.doVerification();
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {}
        String url = TestUtil.getCurrentUrl(driver);
        String redirectURI = SystemProperties.instance().getProperty(
            SystemProperties.RedirectUri
            );
        Assert.assertTrue(
            url.contains(redirectURI) && url.contains("code="),
            "Verify login complete failed."
        );
    }
    
}
